<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="jxl.*" %>
<%@ page import="jxl.write.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生登录</title>
</head>
<body>
<%	
	String str1=request.getParameter("stuid");
	String str2=request.getParameter("password2");
	File fileName = new File("D:/workplace/stuinfo.xls");
	if(!fileName.exists())
	{
		out.print("<script>alert('无此学生信息，请联系管理员添加');</script>");
		out.print("<script>window.location='stulogin.jsp';</script>");
	}
	else
	{
		Workbook book = Workbook.getWorkbook(fileName);
		Sheet sheet=book.getSheet(0); 		/*获得第一个工作表对象*/	
		int rows = sheet.getRows();			/*得到总行数*/
		int temp = 0 , row = 0;
		String password = null;
		for(int i = 1; i<rows; i++)
		{
			Cell cell = sheet.getCell(0, i);
			String stuId = cell.getContents();
			if(str1.equals(stuId))
			{
				Cell cell1 = sheet.getCell(10, i);
				password = cell1.getContents();
				temp = 1;
				row = i;
				break;
			}
		}
		
		if(temp == 1)		/*如果存在该学生信息*/
		{
			if((password.equals(str1))&&(str2.equals(password)))
			{
				%>
				
				<div>第一次登陆，请<a href="stumodifypassword.jsp?stuid=<%= str1%>">修改密码</a></div>
				<%
			}
			else
			{
				if(str2.equals(password))
				{
					request.getRequestDispatcher("stumaininfo.jsp").forward(request,response);
				}
				else
				{
					out.print("<script>alert('密码错误，请返回重新输入');</script>");
					out.print("<script>window.location='stulogin.jsp';</script>");
				}						
			}						
		}
		else
		{
			out.print("<script>alert('无此学生信息，请联系管理员添加');</script>");
			out.print("<script>window.location='stulogin.jsp';</script>");		
		}
	}

%>


</body>
</html>